package cn.itcast.service.cargo.impl;

import cn.itcast.dao.cargo.FactoryDao;
import cn.itcast.domain.cargo.Factory;
import cn.itcast.domain.cargo.FactoryExample;
import cn.itcast.service.cargo.FactoryService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class FactoryServiceImpl implements FactoryService {

    @Autowired
    private FactoryDao factoryDao;
    //保存
    public void save(Factory factory) {
        factoryDao.insertSelective(factory);
    }
    //删除
    public void delete(String id) {
        factoryDao.deleteByPrimaryKey(id);
    }
    //更新
    public void update(Factory factory) {
        factoryDao.updateByPrimaryKeySelective(factory);
    }
    //根据id 查询
    public Factory findById(String id) {
        return factoryDao.selectByPrimaryKey(id);
    }
    //查询全部
    public List<Factory> findAll(FactoryExample example) {
        List<Factory> factories = factoryDao.selectByExample(example);
        return factories;
    }
    //分页查询
    public PageInfo findAll(FactoryExample example, int page, int size) {
        //1.设置分页参数
        PageHelper.startPage(page,size);
        //2.查询全部
        List info = factoryDao.selectByExample(example);
        //3.构造结果
        return new PageInfo(info);
    }
}
